/*
 * File:   NodeTreeTest.cpp
 * Author: KENNJI
 *
 * Created on Mar 26, 2013, 2:02:14 PM
 */

#include "ZipNodeTest.h"
#include "../../src/Tree/ZipTree.h"
#include "../../src/Tree/DirectoryNode.h"
#include "../../src/Tree/ZipNode.h"
#include "../../src/Tree/FileNode.h"

CPPUNIT_TEST_SUITE_REGISTRATION(ZipNodeTest);

ZipNode* nodeToTest;

ZipNodeTest::ZipNodeTest() {
}

ZipNodeTest::~ZipNodeTest() {
}

void ZipNodeTest::setUp() {
    const char* rootName = "root";
    nodeToTest = new DirectoryNode(rootName);

}

void ZipNodeTest::tearDown() {
    delete nodeToTest;
    nodeToTest = 0;
}

void ZipNodeTest::itShouldAddANodeToBranches() {
    const char* fileName = "file1";
    FileNode* fileNode = new FileNode(fileName);
    nodeToTest->addNode(fileNode);
    CPPUNIT_ASSERT(nodeToTest->size() == 1);
}

void ZipNodeTest::itShouldReturnNullWhenTheSearchDoesNotFindASpecificNode() {
    createTree();
    const char* toFind = "asdfasdf";
    ZipNode* nodeRes = nodeToTest->browse(toFind);
    CPPUNIT_ASSERT(nodeRes == NULL);
}

void ZipNodeTest::itShouldReturnAPointerWhenTheSearchEngineFindsASpecificNode() {
    createTree();
    const char* toFind = "root";
    ZipNode* nodeRes = nodeToTest->browse(toFind);
    CPPUNIT_ASSERT(strcmp(nodeRes->getRoot(), toFind) == 0);
}

void ZipNodeTest::itShouldReturnTrueIfTheNodeNameExists() {
    createTree();
    const char* expectedName = "child12";
    CPPUNIT_ASSERT(nodeToTest->contains(expectedName));
}

void ZipNodeTest::itShouldReturnFalseIfTheNodeNameDoesNotExist() {
    createTree();
    const char* falseName = "212316adfasdf";
    CPPUNIT_ASSERT(nodeToTest->contains(falseName) == false);

}

void ZipNodeTest::createTree() {
    const char* name2 = "child";
    const char* name3 = "child11";
    const char* name4 = "child12";

    DirectoryNode* f = new DirectoryNode(name2);
    FileNode* nd = new FileNode(name3);
    FileNode* nd1 = new FileNode(name4);
    f->addNode(nd);
    f->addNode(nd1);
    nodeToTest->addNode(f);
}
